package com.tjetc.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 *
 * 异常处理
 *
 *
 * @author gaoyongxiang
 * @version v1.0
 * @date 2025/9/8
 */
@Controller
@RequestMapping("/exception/")
public class _11ExceptionController {


    // 局部异常
    // 表示该方法是一个异常处理方法
    // 该请求是来自于哪 参数又是什么
//    @ExceptionHandler({ArithmeticException.class})
//    @ExceptionHandler({Exception.class})
    public String handle(Exception e, HttpServletRequest request){
//        System.out.println(request.getParameter("name"));
        System.out.println("处理局部异常");
        System.out.println(e.getMessage());
        return "fail";
    }


    @RequestMapping("f")
    public String f(
            @RequestParam("name") String name
    ){
        try {
            int i = 1 / 0;
        }catch (Exception e){

        }

        return "ok";
    }


    @RequestMapping("f1")
    public String f1(){
        int i = 1 / 0;
//        String s = null;
//        System.out.println(s.length());
        return "ok";
    }




}